<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="renderer" content="webkit">
  <title></title>
  <link rel="stylesheet" href="/Public/Admin/css/pintuer.css">
  <link rel="stylesheet" href="/Public/Admin/css/admin.css">
  <script src="/Public/Admin/js/jquery.js"></script>
  <script src="/Public/Admin/js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 课程列表</strong> </div>
  <div class="padding border-bottom">

    <ul class="search" style="padding-left:10px;">
      <form action="/Admin/Course/index" method="get">
        <ul class="search" style="padding-left:10px;">
          <li>
            <input type="text" placeholder="请输入搜索关键字" name="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" value="{$keywords}" />
          </li>
          <li><input type="submit" class="button border-main icon-search" value="搜索"></li>
          <li>
            <button type="button" class="button border-yellow" onclick="window.location.href='/Admin/Course/addCourse'"><span class="icon-plus-square-o"></span> 添加课程</button>
          </li>
        </ul>
      </form>

    </ul>

  </div>
  <table class="table table-hover text-center">
    <tr>
      <th>课程名</th>
      <th>课程性质</th>
      <th>学分</th>
      <th>任课老师</th>
      <th>上课人数</th>
      <th>已选人数</th>
      <th>上课地点</th>
      <th>上课时间</th>
      <th>课程状态</th>
      <th width="500px">操作</th>
    </tr>
    <?php $num = $pages['page']+1; ?>
    <volist name="lists" id="vo">
      <tr>
        <td style=" padding-left:20px;">{$vo.name}</td>
        <td><if condition="$vo['type'] eq 1">必修课<else/>选修课</if></td>
        <td>{$vo.credit}</td>
        <td>{$vo.teacher}</td>
        <td>{$vo.number}</td>
        <td>{$vo.num}</td>
        <td>{$vo.place}</td>
        <td>{$vo.day}({$vo.time})</td>
        <td>{$vo.statu}</td>
        <td>
          <div class="button-group">
            <a class="button border-main" href="/Admin/Course/addCourse/id/{$vo.id}"><span class="icon-edit"></span>编辑内容</a>
            <a class="button border-main" href="/Admin/Course/addTime/id/{$vo.id}" ><span class="icon-edit"></span> 设置上课时间与地点</a>
            <if condition="$vo['status'] eq 1">
              <a class="button border-main" href="javascript:void(0)" onclick="return start({$vo.id})"><span class="icon-edit"></span> 开始选课</a>
              <else/>
              <a class="button border-main" href="javascript:void(0)" onclick="return end({$vo.id})"><span class="icon-edit"></span> 结束选课</a>
            </if>
            <a class="button border-red" href="javascript:void(0)" onclick="return del({$vo.id})"><span class="icon-trash-o"></span> 删除</a>
          </div>
        </td>
      </tr>
    </volist>
    <tr>
      <td colspan="12">
        <if condition="$lists eq null">
          暂无信息
          <else/>
          <div class="pagelist">
            <a href="/Admin/Product/index/cate_id/{$cate_id}/page/0">首页</a>
            <a href="/Admin/Product/index/cate_id/{$cate_id}/page/{$pages['page']-1}">上一页</a>
            <foreach name="pages.num" item="p">
              <if condition="$p-1 eq $pages['page']">
                <span class="current">{$p}</span>
                <else/>
                <a href="/Admin/Product/index/cate_id/{$cate_id}/page/{$p-1}">{$p}</a>
              </if>
            </foreach>
            <a href="/Admin/Product/index/cate_id/{$cate_id}/page/{$pages['page']+1}">下一页</a>
            <a href="/Admin/Product/index/cate_id/{$cate_id}/page/{$pages['total']}">尾页</a>
          </div>
        </if>
      </td>
    </tr>
  </table>
</div>
<script type="text/javascript">

  $("body").bind("keydown",function(event){
    if (event.keyCode == 116) {
      event.preventDefault(); //阻止默认刷新
      //location.reload();
      //采用location.reload()在火狐下可能会有问题，火狐会保留上一次链接
      location=location;
    }
  })


  function start(id){
    if(confirm("您确定要开始选课吗?")){
      $.ajax({
        url:"/Admin/Course/startData",
        type:"get",
        data:{
          'id':id,
          'status':2,
          'table':'course'
        },
        success:function(data){
          if(data){
            alert("操作成功");
            location.reload();
          }
          else alert("操作失败");
        }
      })
    }
  }

  function end(id){
    if(confirm("您确定要开始选课吗?")){
      $.ajax({
        url:"/Admin/Course/startData",
        type:"get",
        data:{
          'id':id,
          'status':3,
          'table':'course'
        },
        success:function(data){
          if(data){
            alert("操作成功");
            location.reload();
          }
          else alert("操作失败");
        }
      })
    }
  }

  //单个删除
  function del(id){
    if(confirm("您确定要删除吗?")){
      $.ajax({
        url:"/Admin/Course/delData",
        type:"get",
        data:{
          'id':id,
          'table':'course'
        },
        success:function(data){
          if(data == 1){
            alert("删除成功");
            location.reload();
          } else if(data == 2) {
            alert("课程已开始，无法删除");
            location.reload();
          }
          else alert("删除失败");
        }
      })
    }
  }


</script>
</body>
</html>